from django.urls import path
from django.contrib.auth import views as auth_views

from . import views
from .forms import AuthForm

# 编程 不要重复造轮子
# 1. 你自己写得往往可能还不如别人的
# 2. 自己写要耗费很多时间，可以把精力放在更有意义的事情上

# 陆奇 给百度工程师的建议
# vue

SUCCESS_URL = '/success?msg='

app_name = 'users'
urlpatterns = [
    path('register/', views.register, name='register'),
    path('success', views.success, name='success'),

    path('login/', auth_views.LoginView.as_view(
        form_class=AuthForm,
        template_name='form.html',
        extra_context={'title': '登录'}
    ), name='login'),
    path('logout/', auth_views.LogoutView.as_view(
        next_page=SUCCESS_URL + '恭喜你，注销成功！'
    ), name='logout'),

    path('password_change/', auth_views.PasswordChangeView.as_view(
        template_name='form.html',
        success_url=SUCCESS_URL + '恭喜你，密码修改成功！'
    ), name='password_change'),

    path('password_reset/', auth_views.PasswordResetView.as_view(
        template_name='form.html',
        email_template_name='users/password_reset_email.html',
        success_url=SUCCESS_URL + '请登录邮箱完成密码重置！'
    ), name='password_reset'),

    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
        template_name='form.html',
        success_url=SUCCESS_URL + '密码已重置！'
    ), name='password_reset_confirm'),
]
